package com.helei.mq.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 */
@Slf4j
public class RabbitMqUtil {

	private RabbitTemplate rabbitTemplate;

	public RabbitMqUtil(RabbitTemplate rabbitTemplate) {
		this.rabbitTemplate = rabbitTemplate;
	}

	public void sendMessage(String exchange, String routingKey, String messageText){
//		log.info("RabbitMqUtil.sendMessage, 交换机：{}，路由：{}, 消息： {}", exchange, routingKey, messageText);
		rabbitTemplate.convertAndSend(exchange, routingKey, messageText);
	}

    public void sendMessage(String exchange, String routingKey, String messageText, final Integer delayTimes){
//		log.info("RabbitMqUtil.sendMessage, 交换机：{}，路由：{}, 延迟时间:{}, 消息： {}", exchange, routingKey, delayTimes, messageText);
		rabbitTemplate.convertAndSend(exchange, routingKey, messageText, a -> {
			a.getMessageProperties().setDelay(delayTimes);
			return a;
		});
    }


}
